package 笔试.拼多多;

import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        int[] ans = new int[T];
        for(int i=0;i<T;i++){
            int P = in.nextInt();
            int Q = in.nextInt();
            if(P==Q){
                ans[i]=0;
            }else if(P<Q){
                ans[i] = Q-P;
                //乘法优化


            }else{
                ans[i] = (P-Q)/2+(P-Q)%2;
            }
        }
        for (int t : ans) {
            System.out.println(t);
        }


    }


}
